<div class="wrapper">
    <div>
        <div class="box box-top">
            <!-- /.box-header -->
            <!-- form start -->
            <form id="payLogForm" role="form" action="${base}/admin/payLog/recharge" method="post">
                <input type="hidden" name="riderId" value="${(rider.id?c)!}">
                <input type="hidden" name="catagory" value="押金">

                <div class="box-body">
                    <div class="form-group">
                        <label>姓名</label>
                        ${(rider.name)!''}
                    </div>
                    <div class="form-group">
                        <label>手机号</label>
                        ${(rider.phone)!''}
                    </div>
                    <div class="form-group">
                        <label for="packageId">套餐</label>
                        <select name="packageId" id="packageId" class="form-control">
                            <#list rider.depositTypeList as t>
                                <option value="${t.id}">----${t.name}----</option>
                            </#list>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="discountIds">优惠劵</label>
                        <select name="discountIds" id="discountIds" class="form-control">
                            <option value="">----选择优惠劵----</option>
                            <#list rider.discountLogList as t>
                                <option value="${t.id}">----${t.discount.name}----</option>
                            </#list>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="payMoney">金额(计算后的金额)</label>
                        <input type="text" value="" class="form-control" id="payMoney" name="payMoney" >
                    </div>
                    <div class="form-group">
                        <label>附件</label>
                        <div class="row">

                            <div class="col-xs-2" style="width: 12%;">
                                <input type="file" id="exampleInputFile" multiple="multiple">
                            </div>
                            <div class="col-xs-2">
                                <input type="button" value="上传" onclick="pushImg()">
                            </div>
                        </div>
                        <input type="hidden" id="annex" name="img" value="${(payLog.img)!''}">
                    </div>

                    <div class="timeline-body">
                        <img src="${(advertising.titleImg)!'http://placehold.it/150x100'}" alt="..." id="titleImage" class="margin">
                    </div>
                    <div class="box-footer">
                        <button type="button" onclick="$('#payLogForm').submit();" class="btn btn-primary">Save
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function() {
        $("#payLogForm").validate({
            submitHandler:function(form){
                submitRider();
            }
        });
    });
    function submitRider(){
        HF.ajaxFormSubmit('payLogForm',function(result){
            alert("Save Success");
            document.location.reload();
        },function(e){
            alert("Save Failure:"+e.responseText);});
    }
    function pushImg(obj) {

        var url = '${base}'+ "/admin/rider/titleImgeUpload"; //访问控制器是upload，后面必须加'/'否则会报错"org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.Mult...",但是如果是多级的URL【例如XX/XXX/00/upload/0】又没问题了.
        var files = $("#exampleInputFile").get(0).files[0]; //获取file控件中的内容

        var fd = new FormData();
        fd.append("uploadFile", files);
        $.ajax({
            type: "POST",
            contentType:false, //必须false才会避开jQuery对 formdata 的默认处理 , XMLHttpRequest会对 formdata 进行正确的处理
            processData: false, //必须false才会自动加上正确的Content-Type
            url: url,
            data: fd,
            success: function (msg) {

                var obj = eval('(' + JSON.stringify(msg) + ')');
                if(obj.SUCESS){
                    //填充图片
                    $("#titleImage").attr("src", obj.DATA);
                    $("#titleImage").css("width","150");
                    $("#titleImage").css("height","100");
                    //写入隐藏域
                    $("#annex").val(obj.DATA);
                    alert("上传 Success")
                }
            },
            error: function (msg) {
                //debugger;
                alert("error");
            }
        });
    }
</script>
